//!
//! Copyright (c) 2024-2999 北京心月狐科技有限公司 All rights reserved.
//!
//! https://www.mxxshop.com
//!
//! Licensed 并不是自由软件，未经许可不能去掉 MxxShop 相关版权
//!
//! 版权所有，侵权必究！
//!

use actix_session::Session;
use actix_web::{HttpResponse, web};
use actix_web::http::header::ContentType;
use minijinja::context;
use crate::core::errors::error::{Error, Result};
use crate::core::service::template_service::get_template;
use crate::core::web::entity::common::QueryUrl;
use crate::modules::user::service::user_service;

pub async fn user_index(session: Session,path: web::Path<QueryUrl>) -> Result<HttpResponse> {
    let p_short_url = &path.short_url;
    
    let user_info = user_service::get_by_short_url(&p_short_url).await?.ok_or_else(|| { Error::from(format!("msg={},code={}", "未获取到公司信息".to_string(), 404))})?;

    let locale = "zh-CN";
    let ctx = context!(
        title => "MxxShop",
        lang_login => &t!("user.login", locale = locale),
        lang_signup => &t!("user.register", locale = locale)
    );
    let out = get_template("default/user/index.html", ctx)?;
    Ok(HttpResponse::Ok().content_type(ContentType::html()).body(out))
}
